package com.nulldev.util.java.extendedUI.cSwing;

import java.awt.Graphics2D;

import com.nulldev.util.java.JVMUtil;
import com.nulldev.util.java.swing.canvas.PaintMethod;
import com.nulldev.util.java.swing.canvas.SmoothCanvas;
import com.nulldev.util.java.utils.color.ColorUtil;

public class cProgressBar extends SmoothCanvas {
	
	private float percent;
	
	public cProgressBar() {
		super();
		setFPS(60);
		usePaintMethod(PaintMethod.REPAINT);
		setAAEnabled(true);
	}

	@Override
	public void drawCanvas(Graphics2D g2d) {
		g2d.setColor(this.getForeground());
		g2d.fillRect(0, 0, getWidth(), getHeight());
		g2d.setColor(ColorUtil.rainbow(200, 1.0f));
		g2d.fillRect(0, 0, (int) (this.getWidth() / (100 / this.percent)), this.getHeight());
	}

	public float getPercent() {
		return this.percent;
	}
	
	public void setPercent(final float percent) {
		if (percent < 0 || percent > 100) {
			return;
		}
		this.percent = percent;
	}
}
